package Lesson19Homework;
import java.util.Scanner;
public class SecuredNotepad extends SimpleNotepad implements ISecuredNotepad {
	private final String password;
	
	SecuredNotepad(int numberOfPages, String password)
	{
		super(numberOfPages);
		this.password = password;
	}
	
	@Override
	public void addText(int pageNumber, String newText) 
	{
		if(askForPassword())
			super.addText(pageNumber, newText);
	}
	
	@Override
	public void replaceTextInPage(int pageNumber, String newText) 
	{
		if(askForPassword())
			super.replaceTextInPage(pageNumber, newText);
	}
	
	public void deleteText(Page selectedPage) 
	{
		if(askForPassword())
			super.deleteText(selectedPage);
	}
	
	@Override
	public void viewPages() 
	{
		if(askForPassword())
			super.viewPages();
	}

	@Override
	public boolean askForPassword() 
	{
		Scanner s = new Scanner(System.in);
		return s.next().equals(password);
	}
}
